function [Q,freq1,freq2]=calculateQ(data,freq,iBP,CF,iCFoI,maxAct,n)


data=squeeze(abs(data(iBP,:)));

freqInterp=linspace(freq(1),freq(end),1001);
dataInterp=interp1(freq,data,freqInterp);

[maxAct,iPeak]=max(dataInterp);


    i1=NaN;
        i2=NaN;
       for iFreq=iPeak-1:-1:1
           if 20*log10(abs(dataInterp(iFreq)))<20*log10(maxAct)-n
               i1=iFreq;
               break
           end
       end
       for iFreq=iPeak+1:1:length(freqInterp)
           if 20*log10(abs(dataInterp(iFreq)))<20*log10(maxAct)-n
               i2=iFreq;
               break
           
           end
       end
       if and(i1>1,i2<length(freqInterp))
            Q=CF/(freqInterp(i2)-freqInterp(i1));
       else
           Q=NaN;
       end
      

       freq1=freqInterp(i1);
       freq2=freqInterp(i2);

end